<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" @selection-change="e => selection = e" ref="SuperTablePage">
    </ex_super_table_page>
    <add_commodity_sku_relationship_dialog ref="addCommoditySkuRelationshipDialog" @getList="getList" :dialogData="dialogData" />
  </div>
</template>

<script>
import superTablePageFunction from "@/mixin/super-table-page-function";
import page_table_model_manage from "@/mixin/page_table_model_manage";
import emitOnFunction from "@/mixin/emit-on-function";
import add_commodity_sku_relationship_dialog from "@/page/oms/purchase/dialog/add_commodity_sku_relationship_dialog.vue"
let emitKey = "oms>purchase>commodity_sku_relationship_set";
export default {
  title: 'label_purchase_commodity_sku_relationship_set',
  mixins: [
    superTablePageFunction,
    emitOnFunction(emitKey),
    page_table_model_manage,
  ],
  components:{
    add_commodity_sku_relationship_dialog
  },
  props:{
  },
  data () {
    return {
      dialogData: {
        skuOnlyCode: '',
        customerId: '', // 客户id
      },
      option: {
        search: {
          formDataHandle: (data) => {
            data.skuId = this.$route.query.id
            data.customerId = this.$route.query.customerId
            return data
          },
          model: [
            // {
            //   label: "商品SKU",
            //   key: "skuId",
            // },
          ],
        },
        action: [
          {
            label: "label_supplier_batch_remove",
            // auth: "oms_purchase_supplier_edit",
            click: this.batchRemove,
          },
        ],
        actionExtra: [
          {
            label: "label_add_supplier",
            // auth: "oms_purchase_supplier_edit",
            click: () => {
              this.$refs.addCommoditySkuRelationshipDialog.show()
            },
          },
        ],

        table: {
          url: "/oms-api/purchase/OmsPurchaseSupplierRefRpc/selectSupplierRefPage.json",
          attrs: {},
          model: this.init_table_model(),
        },
      }
    }
  },
  watch: {
  },
  computed: {
    
  },
  created () {
    this.dialogData.customerId = this.$route.query.customerId
    this.dialogData.skuOnlyCode = this.$route.query.skuOnlyCode
  },
  mounted () {
    
  },
  methods: {
    getList() {
      this.$refs.SuperTablePage.reload()
    },
    batchRemove() {
      if (!this.selection || this.selection.length === 0) {
        return
      }
      this.$ajax({
        url: "/oms-api/purchase/OmsPurchaseSupplierRefRpc/deleteSupplierRef.json",
        type: 'json',
        data: {ids: this.selection.map(item => item.id)},
        success: (res) => {
          if(res.code === 0) {
            this.$refs.SuperTablePage.clearSelection();
            this.$message.success(this.$tt('tip_operate_success'))
            this.getList()
          }
        },
      });
    },
    option_table_model() {
      return [
        {
          type: "selection",
          clickToggle: true,
          keyGroup: "label_table_operate",
        },
        {
          key: "supplierName",
          label: "label_supplier_good_name",
          "show-overflow-tooltip": true,
        },
        {
          key: "gmtCreate",
          label: "label_create_time",
          formatter: (r, c, v, i) => (v ? this.$dateFormat(r["gmtCreate"]) : "-"),
        },

        {
          type: "operate",
          width: 150,
          operate: [
            {
              label: "label_delete",
              auth: 'oms_purchase_supplier_edit',
              type: "confirm-button",
              urlType: "json",
              url: '/oms-api/purchase/OmsPurchaseSupplierRefRpc/deleteSupplierRef.json',
              message: 'label_fms_bank_card_confirm_delete',
              params: (v) => {
                return {ids: [v.id]}
              },
              done: ['reload', 'tip']
            },
          ],
        },
      ];
    },
    
  },
  destroyed () {
    
  }
};
</script>

<style lang="less" scoped>
/deep/.table-page-body {
  .search {
    display: none;
  }
}

</style>